using UnityEngine;
using System.Collections;

public class BomberHard : MonoBehaviour 
{
	public AudioSource dropBombSound;
	public int moveSpeed = 60;
	public bool isComputer = false;
	Vector3 computerDirection = Vector3.right;
	public bool onScreen = true;
	public Transform Bomb;
	public int bombCount = 0;

	// Use this for initialization
	void Start () 
	{
		InvokeRepeating("BombDrop", 1, 1);
	}
	
	// Update is called once per frame
	void Update () 
	{
		Vector3 newPosition = Vector3.zero;
		newPosition = computerDirection * (moveSpeed * Time.deltaTime);
		
		newPosition = newPosition + transform.position;
		
		if(newPosition.x > 20)
		{
			newPosition.x = 20;
			computerDirection.x *= -1;
		}
		
		else if(newPosition.x < -20)
		{
			newPosition.x = -20;
			computerDirection.x *= -1;
		}
		
		transform.position = newPosition;
	}
	
	void BombDrop()
	{
		if(onScreen == true)
		{
			if(bombCount < 60)
			{
				dropBombSound.Play();
				Transform newBomb = Instantiate(Bomb, transform.position, transform.rotation) as Transform;
				bombCount++;
				
				if(bombCount >= 60)
				{
					Destroy(gameObject);
					bombCount = 61;
					if(bombCount == 61)
					{
						Application.LoadLevel("MainMenu");
					}
				}
			}
		}
	}
}
